package com.vogue.meeting.common.security.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.security.core.AuthenticatedPrincipal;
import org.springframework.security.core.CredentialsContainer;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;
import java.util.Set;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Oauth2User implements UserDetails,AuthenticatedPrincipal,CredentialsContainer,Serializable {

    /**
     * 用户ID
     */
    private Integer id;

    /**
     * 昵称
     */
    private String nickName;

    /**
     * 账号
     */
    private String account;

    /**
     * 密码
     * {@link org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder#matches }
     */
    private String password;

    /**
     * 启用
     */
    private Boolean enable;
    /**
     * 锁定
     */
    private Boolean locked;
    /**
     * 权限
     */
    private Collection<? extends GrantedAuthority> authorities;

    @Override
    public String getName() {
        return this.account;
    }

    @Override
    public String getUsername() {
        return this.account;
    }

    @Override
    public String getPassword() {
        return this.password;
    }

    @Override
    public boolean isAccountNonExpired() {
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        return !this.locked;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return false;
    }

    @Override
    public boolean isEnabled() {
        return this.enable;
    }

    @Override
    public void eraseCredentials() {

    }
}
